home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog5.arj / PEN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  1.9 KB  |  90 lines

  1. { pen.pas -- Select pen styles }
  2.  
  3. program PenStyles;
  4.  
  5. uses WinTypes, WinProcs, WObjects;
  6.  
  7. type
  8.  
  9.   PenApplication = object(TApplication)
  10.     procedure InitMainWindow; virtual;
  11.   end;
  12.  
  13.   PPenWindow = ^PenWindow;
  14.   PenWindow = object(TWindow)
  15.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  16.     procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
  17.       virtual;
  18.   end;
  19.  
  20. { PenApplication }
  21.  
  22. {- Initialize the application's window }
  23. procedure PenApplication.InitMainWindow;
  24. begin
  25.   MainWindow := New(PPenWindow, Init(nil, 'Pen Styles'))
  26. end;
  27.  
  28. { PenWindow }
  29.  
  30. {- Initialize the application's window object }
  31. constructor PenWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  32. begin
  33.   TWindow.Init(AParent, ATitle);
  34.   with Attr do
  35.   begin
  36.     X := 20; Y := 20; W := 411; H := 250
  37.   end
  38. end;
  39.  
  40. {- Paint graphics in window }
  41. procedure PenWindow.Paint(PaintDC: HDC; var PaintInfo:
  42.   TPaintStruct);
  43. var
  44.   X, Delta, Width: Integer;
  45.   R: TRect;
  46.  
  47.   procedure DrawLine(Style, Width: Integer);
  48.   var
  49.     OldPen, ThePen: HPen;
  50.   begin
  51.     ThePen := CreatePen(Style, Width, RGB(0, 0, 0));
  52.     OldPen := SelectObject(PaintDC, ThePen);
  53.     MoveTo(PaintDC, X, 4);
  54.     LineTo(PaintDC, X, R.Bottom - 4);
  55.     X := X + Delta;
  56.     SelectObject(PaintDC, OldPen);
  57.     DeleteObject(ThePen)
  58.   end;
  59.  
  60. begin
  61.   GetClientRect(HWindow, R);
  62.   X := 10;
  63.   Delta := R.Right div 20;
  64.   for Width := 1 to 4 do
  65.   begin
  66.     DrawLine(ps_Solid, Width);
  67.     DrawLine(ps_Dash, Width);
  68.     DrawLine(ps_Dot, Width);
  69.     DrawLine(ps_DashDot, Width);
  70.     DrawLine(ps_DashDotDot, Width)
  71.   end
  72. end;
  73.  
  74. var
  75.  
  76.   PenApp: PenApplication;
  77.  
  78. begin
  79.   PenApp.Init('PenApp');
  80.   PenApp.Run;
  81.   PenApp.Done
  82. end.
  83.  
  84.  
  85. {--------------------------------------------------------------
  86.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  87.   Revision 1.00    Date: 2/20/1991
  88. ---------------------------------------------------------------}
  89.  
  90.